package com.kzd.sdk.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.kzd.sdk.callback.KZD_OnItemClickListener;
import com.kzd.sdk.entity.KZD_GameRebate;
import com.kzd.sdk.ui.adapter.holder.GameRebateHolder;
import com.kzd.sdk.utils.AppUtils;

import java.util.ArrayList;
import java.util.List;


public class KZD_GameRebateAdapter extends RecyclerView.Adapter<GameRebateHolder> {

    private List<KZD_GameRebate.List> data = new ArrayList<>();

    private final Context mContext;

    private KZD_OnItemClickListener mOnItemClickListener;

    public KZD_GameRebateAdapter(Context context) {
        this.mContext = context;
    }

    @NonNull
    @Override
    public GameRebateHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(AppUtils.getLayoutId(mContext, "kzd_item_game_rebate"), parent, false);
        return new GameRebateHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull GameRebateHolder holder, int position) {
        KZD_GameRebate.List itemData = get(position);
        holder.tvGameRebateName.setText(itemData.getServer_name());
        holder.tvGameRebateRole.setText(new StringBuilder("角色名称：").append(itemData.getRole_name()));
        holder.tvGameRebateMoney.setText(new StringBuilder("+").append(itemData.getMoney()));
        holder.tvGameRebateTime.setText(itemData.getTime());
        //0待审核1已发放2已拒绝3可以申请
        String statusStr = "";
        switch (itemData.getStatus()) {
            case "0":
                statusStr = "待审核";
                break;
            case "1":
                statusStr = "已发放";
                break;
            case "2":
                statusStr = "已拒绝";
                break;
            default:
                statusStr = "去申请";
                break;
        }
        holder.tvGameRebateStatus.setText(statusStr);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.onClick(v, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setNewInstance(List<KZD_GameRebate.List> rebateLists) {
        if (rebateLists == null) {
            this.data = new ArrayList<>();
        } else {
            this.data = rebateLists;
        }
        notifyDataSetChanged();
    }

    public KZD_GameRebate.List get(int position) {
        return data.get(position);
    }

    public void setOnItemClickListener(KZD_OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
